<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline">

      <el-form-item>
        <el-select
            v-model="searchObj.department"
            placeholder="请选择学院"
            @change="departmentChanged">
          <el-option
              v-for="item in departmentList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-date-picker
            v-model="searchObj.date"
            align="right"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
            :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>

      <el-checkbox v-model="searchObj.healthCon">身体不良</el-checkbox>
      <el-checkbox v-model="searchObj.impRegion">15天内接触重点防疫地区</el-checkbox>

      <el-button type="primary" icon="el-icon-search" @click="fetchReportInfo('1')">查询</el-button>
      <el-button type="primary" icon="el-icon-search" @click="getUnReported">查询今天</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>




    </el-form>

    <!-- banner列表 -->
    <el-table v-loading="listLoading" :data="list"
              border
              fit
              highlight-current-row>

      <el-table-column
          label="编号"
          width="60"
          align="center">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>

      <!--      <el-table-column label="姓名">-->
      <!--        <template slot-scope="scope">-->
      <!--          <img :src="'data:image/jpeg;base64,'+scope.row.logoData" width="80">-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <el-table-column prop="name" label="姓名"width="90"/>
      <el-table-column prop="idNumber" label="身份证" />
      <el-table-column prop="university" label="学校"/>
      <el-table-column prop="department" label="学院"/>
      <el-table-column prop="healthCon" label="健康状态"/>

      <el-table-column prop="temperature" label="体温（度）"/>
      <el-table-column prop="location" label="所在地"/>
      <el-table-column label="是否处于隔离状态">
        <template slot-scope="scope">
          {{ scope.row.isolated == 1 ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column label="是否为重点人群">
        <template slot-scope="scope">
          {{ scope.row.focusGroups == 1 ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column label="是否与感染者接触">
        <template slot-scope="scope">
          {{ scope.row.virusTouch == 1 ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column prop="reportDate" label="上报日期"/>
      <!--      <el-table-column prop="createTime" label="创建时间"/>-->
      <el-table-column label="操作" width="230" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="catDetails">详细内容</el-button>
        </template>

      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
        :current-page="currentPage"
        :total="total"
        :page-size="limit"
        style="padding: 30px 0; text-align: center;"
        @current-change="fetchReportInfo"
    />
  </div>
</template>

<script>
import userManagerApi from "@/views/api/userManager";
import popMessage from "@/utils/popMessage";
import request from "@/utils/request";
export default {
  name:"HealthList",
  data() {
    return {
      listLoading: false, // 数据是否正在加载
      list: null, //
      total: 0, // 数据库中的总记录数
      currentPage: 1, // 默认页码
      limit: 5, // 每页记录数
      searchObj: {
      }, // 查询表单对象
      departmentList: [],   //所有学院集合
      statusReport:false,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },

    }
  },
  mounted() {

    this.fetchReportInfo()

  },
  created() {
    this.findAllDepartMent();

  },
  activated() {
  },
  methods: {


    exportData()
    {
      request({
        url: '/api1/api/exportUnReported',
        method: 'post',
        headers:'Content-Type: multipart/form-data',
      }).then(res=>{

        this.$router.push(this.$route.params.path)

      })
    },


    //查询用户信息
    fetchReportInfo(page=1) {
      console.log(page)
      this.currentPage = page
      console.log("dadsadasfgretrfhewhtrwegtrfhegrf")
      console.log(this.currentPage)
      let data={
        currentPage:this.currentPage,
        department: this.searchObj.department,
        healthCon:this.searchObj.healthCon===false?1:0,
        impRegion:this.searchObj.impRegion===false?1:0
      }
      userManagerApi.getReported(data).then(res=>{

        console.log(res.data)
        this.list=res.data.data.infos;
        this.total=res.data.data.total


      })
    },

    findAllDepartMent(){
      userManagerApi.getAllDepartMent(null,{name:"学院"}).then(res=>
      {

        console.log(res.data)
        this.departmentList=res.data.data
      }).catch(error=>
      {
        postMessage(false,"获取数据失败","error")
        /*postMessage(true,"获取数据失败","error")*/
        // console.log(error)
      })
    },

    departmentChanged() {

      console.log(this.searchObj.department)
      console.log(this.currentPage)
    },
    resetData(){
      this.currentPage=1;
      this.searchObj={};
    },
  }
}
</script>

<style scoped>

</style>
